<?php

namespace App\Services\Login;

use App\Utils\LoggerUtil;
use AppleSignIn\ASDecoder;

class AppleLoginService
{
    public static function getAppleInfo($user, $identityToken)
    {
        // composer require griffinledingham/php-apple-signin
        try {
            $appleSignInPayload = ASDecoder::getAppleSignInPayload($identityToken);
            if ($appleSignInPayload->verifyUser($user)) {
                $appleUid = $appleSignInPayload->getUser(); // apple_uid
                return ['appleId' => $appleUid];
            }
            return [];
        } catch (\Throwable $e) {
            LoggerUtil::write("apple_user_info", $e->getFile() . ':(' . $e->getLine() . ')@' . $e->getMessage());
            return [];
        }

    }

}